// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ChineseTokenizerFactory.java

import java.io.Reader;
import java.util.Map;
import net.paoding.analysis.analyzer.PaodingTokenizer;
import net.paoding.analysis.analyzer.TokenCollector;
import net.paoding.analysis.analyzer.impl.MaxWordLengthTokenCollector;
import net.paoding.analysis.analyzer.impl.MostWordsTokenCollector;
import net.paoding.analysis.knife.PaodingMaker;
import org.apache.lucene.analysis.TokenStream;
import org.apache.solr.analysis.BaseTokenizerFactory;

public class ChineseTokenizerFactory extends BaseTokenizerFactory
{

    public ChineseTokenizerFactory()
    {
        mode = null;
    }

    public void setMode(String mode)
    {
        if(mode == null || "most-words".equalsIgnoreCase(mode) || "default".equalsIgnoreCase(mode))
            this.mode = "most-words";
        else
        if("max-word-length".equalsIgnoreCase(mode))
            this.mode = "max-word-length";
        else
            throw new IllegalArgumentException((new StringBuilder("\u4E0D\u5408\u6CD5\u7684\u5206\u6790\u5668Mode\u53C2\u6570\u8BBE\u7F6E:")).append(mode).toString());
    }

    public void init(Map args)
    {
        super.init(args);
        setMode((String)args.get("mode"));
    }

    public TokenStream create(Reader input)
    {
        return new PaodingTokenizer(input, PaodingMaker.make(), createTokenCollector());
    }

    private TokenCollector createTokenCollector()
    {
        if("most-words".equals(mode))
            return new MostWordsTokenCollector();
        if("max-word-length".equals(mode))
            return new MaxWordLengthTokenCollector();
        else
            throw new Error("never happened");
    }

    public static final String MOST_WORDS_MODE = "most-words";
    public static final String MAX_WORD_LENGTH_MODE = "max-word-length";
    private String mode;
}
